<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\widgets\FileInput;

/* @var $this yii\web\View */
/* @var $model common\models\Brand */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="brand-form">

    <?php $form = ActiveForm::begin(['options' => ['enctype'=>'multipart/form-data']]); ?>
    
    <?= $form->field($model, 'name')->textInput(['maxlength' => 45]) ?>
    
    <?php
    $opt = [
        'showUpload' => false,
        'showCaption' => false,
        'allowedFileExtensions' => ['jpg', 'gif', 'png'],
    ];

    if (!$model->isNewRecord) {
        $img = Yii::$app->params['urls']['img'] . $model->logo;
        $opt['initialPreview'] = ["<img src='{$img}' class='file-preview-image'>"];
    }

    echo $form->field($model, 'logo')->widget(FileInput::classname(), [
        'options' => ['accept' => 'image/*'],
        'pluginOptions' => $opt,
    ]);
    ?>
    
    <?= $form->field($model, 'desc')->textarea(['rows' => 6]) ?>

    <?= $form->field($model, 'site')->textInput(['maxlength' => 200]) ?>

    <?= $form->field($model, 'sort_order')->textInput(['maxlength' => 10]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '新建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
